
#include "iopmp_cfg.h"
#include "datatype.h"
#include "stdio.h"

void iopmp_config_enable(char iopmpID,unsigned int en_disen)
{
  REG32(IOPMP_BASE + IOPMP_ID_REG) = ((en_disen<<5)&0x00000020) | (iopmpID&0x0000001F); //'b100001
}

void siopmp_rule_set(char Device,char rule)
{
   iopmp_config_enable(1,1);
   REG32(IOPMP_BASE + SIOPMP_RULE_REG) = (((unsigned int)rule) << (Device<<1)) | (~(0x3<<(Device<<1)));
   iopmp_config_enable(0,0);
}


void diopmp_rule_set(char Device,diopmp_config *diopmp_config )
{
   iopmp_config_enable(3,1);
  //  REG32(IOPMP_BASE + SIOPMP_RULE_REG) = (((unsigned int)rule) << (Device<<1)) | (~(0x3<<(Device<<1)));
  REG32(IOPMP_BASE + DIOPMP_BEGIN_CNT_REG) = diopmp_config->begin_cnt;
  REG32(IOPMP_BASE + DIOPMP_DSIZE_CNT_REG) = diopmp_config->size_cnt;
  REG32(IOPMP_BASE + DIOPMP_RULE_REG) = diopmp_config->rule;
  REG32(IOPMP_BASE + DIOPMP_MODE_REG) = diopmp_config->mode;
   iopmp_config_enable(0,0);
}


uint32_t siopmp_rule_read(void)
{
    uint32_t data=0;
   iopmp_config_enable(1,0);
   data = REG32(IOPMP_BASE + SIOPMP_RULE_REG);
   iopmp_config_enable(0,0);
   return data;
}

void diopmp_rule_read(void)
{
    uint32_t data=0;
   iopmp_config_enable(2,0);
   printf("diopmp begin count: 0x%x\n",REG32(IOPMP_BASE + DIOPMP_BEGIN_CNT_REG));
   printf("diopmp size count: 0x%x\n",REG32(IOPMP_BASE + DIOPMP_DSIZE_CNT_REG));
   printf("diopmp rule: 0x%x\n",REG32(IOPMP_BASE + DIOPMP_RULE_REG));
   printf("diopmp mode: 0x%x\n",REG32(IOPMP_BASE + DIOPMP_MODE_REG));
   
   iopmp_config_enable(0,0);
   return data;
}